package project.newCode.surfaces;

import java.util.ArrayList;

import project.newCode.Hitrecord;
import project.newCode.Ray;

public class Group extends Surface{

	private ArrayList<Surface> S;
	public Group() {
		S = new ArrayList<Surface>();
	}
	public Group(ArrayList<Surface> Snew) {
		S = Snew;
	}
	
	public void add(Surface s1) {
		S.add(s1);
	}
	@Override
	public boolean hit(Ray hittingray, double t0, double t1, Hitrecord rec) {
		boolean hit = false;
		for(int i = 0; i<getS().size(); i++) {
			if(getS().get(i).hit(hittingray, t0, t1, rec)) {
				hit = true;
				t1 = rec.t;
			}
		}
		return hit;
	}

	@Override
	public Box boundingbox() {
		// TODO Auto-generated method stub
		return null;
	}

	public ArrayList<Surface> getS() {
		return S;
	}

	public void setS(ArrayList<Surface> s) {
		S = s;
	}

	@Override
	public Surface surfaceClone() {
		ArrayList<Surface> Snew=new ArrayList<Surface>();
		for(Surface s: S) {
			Snew.add(s.surfaceClone());
		}
		return new Group(Snew);
	}

}
